<template><!-- 
    ref:
    data: 全部的数据
    selection-change: 每一项操作会触发
    el-table-column： 是每一列

     作用域插槽  如果不能直接拿到数据，就需要作用域插槽 
      <template #default="scope">{{ scope.row.date }}</template> 

     property接收tableData里的数据， 
     <el-table-column property="name" label="Name" width="120" /> 
 -->

     <el-table class="contentBox" ref="multipleTableRef" 
        :data="playLists" 
        style="width: 100%"
        @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="60" />

         <!-- 数据需要处理一下 =》 多个数据合并起来。 label是表头名称  -->
         <el-table-column label="直播信息" width="210">
             <!-- scope 表示：playLists中的每一项，是对象{}; scope.row 是对象里的每一项 -->
             <template #default="scope"> <!-- 可以在这里面写布局 -->
                 <div class="w-flex2">
                     <img class="imgBox" :src="scope.row.img" alt="">
                     <div class="desc"> {{ scope.row.name }} </div>
                 </div>
             </template>
         </el-table-column>
         <el-table-column property="Pstatus" label="直播状态" width="110" />
         <el-table-column property="nums" label="预约人数" width="100" />
         <!-- <el-table-column property="Shstatus" label="商品状态" width="120" /> -->
         <el-table-column label="商品状态" width="120">
             <template #default="scope"> <!-- 可以在这里面写布局 -->
                 <div class="itemColor"> {{ scope.row.Shstatus }} </div>
             </template>
         </el-table-column>
         <el-table-column property="time" label="开始时间" width="200" />
         <el-table-column type="index" label="序号" width="70" />
         <el-table-column label="操作" width="200">
             <!-- scope 表示：playLists中的每一项，是对象{}; scope.row 是对象里的每一项 -->
             <template #default="scope"> <!-- 可以在这里面写布局 -->
                 <div class="w-flex2 opra">
                     <div class="desc">数据</div>
                     <div class="desc">编辑</div>
                     <div class="desc">下架</div>
                     <div class="desc">删除</div>
                 </div>
             </template>
         </el-table-column>

         <!-- <el-table-column label="Date" width="120">
                 <template #default="scope">{{ scope.row.date }}</template>
             </el-table-column>
             <el-table-column property="name" label="Name" width="120" />
             <el-table-column property="address" label="Address" show-overflow-tooltip /> -->
     </el-table>

 <!-- <div style="margin-top: 20px">
        <el-button @click="toggleSelection([tableData[1], tableData[2]])">Toggle selection status of second and third
            rows</el-button>
        <el-button @click="toggleSelection()">Clear selection</el-button>
    </div> -->
    </template>

<script lang="ts" setup>
import { ref } from 'vue'
import { ElTable } from 'element-plus'

// 自己写的
defineProps({
    playLists: {   // 内部数据(如 playLists)在 模板上使用 不需要watch监听
        type: Array,  // 后端传的数据  [{}],  只读 的响应式数据
    }
})

interface User {
    date: string
    name: string
    address: string
}

const multipleTableRef = ref<InstanceType<typeof ElTable>>()
const multipleSelection = ref<User[]>([])
const toggleSelection = (rows?: User[]) => {
    if (rows) {
        rows.forEach((row) => {
            // TODO: improvement typing when refactor table
            // eslint-disable-next-line @typescript-eslint/ban-ts-comment
            // @ts-expect-error
            multipleTableRef.value!.toggleRowSelection(row, undefined)
        })
    } else {
        multipleTableRef.value!.clearSelection()
    }
}
const handleSelectionChange = (val: User[]) => {
    multipleSelection.value = val
}

const tableData: User[] = [
    {
        date: '2016-05-03',
        name: 'Tom',
        address: 'No. 189, Grove St, Los Angeles',
    },
    //     {
    //     name:'H5进阶课程',
    //     img:'',
    //     Patatus:'未开始',
    //     nums:'20',
    //     Shstatus:'已上架',
    //     time:'2023/2/18 16:00'
    //   },
    {
        date: '2016-05-02',
        name: 'Tom',
        address: 'No. 189, Grove St, Los Angeles',
    },
    {
        date: '2016-05-04',
        name: 'Tom',
        address: 'No. 189, Grove St, Los Angeles',
    },
    {
        date: '2016-05-01',
        name: 'Tom',
        address: 'No. 189, Grove St, Los Angeles',
    },
    {
        date: '2016-05-08',
        name: 'Tom',
        address: 'No. 189, Grove St, Los Angeles',
    },
    {
        date: '2016-05-06',
        name: 'Tom',
        address: 'No. 189, Grove St, Los Angeles',
    },
    {
        date: '2016-05-07',
        name: 'Tom',
        address: 'No. 189, Grove St, Los Angeles',
    },
]
</script>

<style scoped lang="scss">
.contentBox {

    .imgBox {
        max-width: 80px;
        margin-right: 10px;
    }
    .itemColor{
        color: rgb(18, 210, 108);
    }
    .desc{
        color: rgb(49, 103, 252);
        margin-left: 10px;
        margin-right: 0;
    }
    .opra{
        justify-content: space-between;
        padding-right: 10px;
    }

}
</style>